<?php
/**
 * Created by jinqiang on 2024/6/6 10:10.
 * Copyright (c) 2024, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Banshi;


use App\Http\Controllers\Controller;
use App\Http\Services\Banshi\BaseCodeService;
use Illuminate\Http\Request;

class BaseCodeController extends Controller
{
    public function list(Request $request, BaseCodeService $baseCodeService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $baseCodeService->search($param);
        return result($res);
    }

    public function status(Request $request, BaseCodeService $baseCodeService)
    {
        $this->validate($request, [
            'id' => 'required',
            'status' => 'required'
        ]);
        $param = $request->all();
        $res = $baseCodeService->setStatus($param['id'], $param['status']);
        return $res['code'] === 0 ? success("更新成功") : error($res['msg'], $res);
    }

    public function set(Request $request, BaseCodeService $baseCodeService)
    {
        $this->validate($request, [
            'data' => 'required'
        ]);
        $param = json_decode($request->input('data'), true);
        if(empty($param['base_category']) || empty($param['type']) || empty($param['base_size_code'])){
            return error("内容不能为空");
        }
        $id = $param['id'] ?? "";
        $res = $baseCodeService->setData($id, $param);
        return $res['code'] === 0 ? success("设置成功") : error($res['msg'], $res);
    }
}
